﻿package com.tomvian.twodee.common.interactions 
{
	import flash.display.DisplayObject;
	import flash.display.InteractiveObject;
	import flash.display.MovieClip;
	import sfb.engines.core.control.Controller;
	import com.tomvian.twodee.common.Actor;
	import com.tomvian.maths.Vector2D;
	import sfb.physics.Mass;
	/**
	 * Interaction
	 * @author Thomas Vian
	 */
	public class Interaction
	{
		//--------------------------------------------------------------------------
		//
		//  Properties
		//
		//--------------------------------------------------------------------------
		
		protected var _enabled:Boolean = true;
		
		public var interactiveObjects:Array;
		
		public var interactionNodes:InteractionNode;
		
		public var currentObject:DisplayObject;
		
		public var interacting:Boolean;
		public var wasInteracting:Boolean;
		
		public var cameraOffset:Vector2D;
		
		public var next:Interaction;
		public var last:Interaction;
		
		protected var _testPoint:Vector2D;
		
		//--------------------------------------------------------------------------
		//
		//  Getters / Setters
		//
		//--------------------------------------------------------------------------
		
		
		//--------------------------------------------------------------------------
		//
		//  Constructor
		//
		//--------------------------------------------------------------------------
		
		public function Interaction(interactiveObjects:Array) 
		{
			this.interactiveObjects = interactiveObjects;
			
			_testPoint = new Vector2D();
		}
		
		//--------------------------------------------------------------------------
		//
		//  Methods
		//
		//--------------------------------------------------------------------------
		
		public function addActor(actor:Actor, interactionPoint:Vector2D = null, nodeClass:Class = null):InteractionNode
		{
			var node:InteractionNode;
			
			if (nodeClass) 	node = new nodeClass(actor) as InteractionNode;
			else 			node = new InteractionNode(actor);
			
			if (interactionPoint) node.interactionPoint = interactionPoint;
			
			if (!interactionNodes) 
			{
				interactionNodes = node;
			}
			else
			{
				node.next = interactionNodes;
				interactionNodes.prev = node;
				interactionNodes = node;
			}
			
			return node;
		}
		
		public function addActors(actors:Array, interactionPoints:Array = null, nodeClass:Class = null):void
		{
			var point:Vector2D;
			
			if (interactionPoints && interactionPoints.length == 1) point = interactionPoints[0];
			
			for (var i:uint = 0, l:uint = actors.length; i < l; i++)
			{
				var node:InteractionNode;
				
				if (nodeClass) 	node = new nodeClass(actors[i]) as InteractionNode;
				else 			node = new InteractionNode(actors[i]);
				
				if (interactionPoints)
				{
					if (point) 	node.interactionPoint = point;
					else 		node.interactionPoint = interactionPoints[i];
				}
				
				if (!interactionNodes) 
				{
					interactionNodes = node;
				}
				else
				{
					node.next = interactionNodes;
					interactionNodes.prev = node;
					interactionNodes = node;
				}
			}
		}
		
		public function interact():void
		{
			
		}
		
	}
}